package light.head.dao.sys;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import light.head.constant.Parm;
import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.PageBean;
import light.head.model.UserAnnex;
/***
 * 
 * @author yy
 *
 */
@Service
public class UserAnnexDAO extends BaseDAO<UserAnnex, Integer>{
	
	public RESULT findByMap(Map<String, String> map, PageBean pageBean) {
		StringBuffer hql = new StringBuffer("FROM UserAnnex ua WHERE ua.deleted = 0");
		
		List<Object> list = null;
		if (map != null) {
			list = new ArrayList<Object>();
			String name = map.get(Parm.NAME);
			if (isNotNull(name)) {
				hql.append(" AND ua.name LIKE ?");
				list.add("%" + name + "%");
			}
		}
		hql.append(" ORDER BY ua.code");
		return findToPageBean(hql.toString(), pageBean, list);
	}
	
	
	public RESULT update(UserAnnex ua) {
		if(null == ua || null == ua.getCode()) return RESULT.PARAMETER_ERROR;
		
		UserAnnex old = get(ua.getCode());
		if(isNotNull(ua.getName())) {
			old.setName(ua.getName());
		}
		
		RESULT result = upd(old);
		return result;
	}
	
	public UserAnnex findUserAnnexByUuid(String uuid){
		if(null == uuid)  return null;
		
		StringBuffer sql = new StringBuffer("FROM UserAnnex ua WHERE ua.uuid = ?");
		List<UserAnnex> list = find(sql.toString(), uuid);
		return list.get(0);
	}

}
